package krow.dev.gunpobus.view.adapter;

import java.util.ArrayList;
import java.util.List;

import krow.dev.gunpobus.model.ScheduleItem;
import krow.dev.gunpobus.util.ItemViewFactory;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class ScheduleListAdapter extends BaseAdapter{

	private LayoutInflater mLayoutInflater;

	private List<ScheduleItem> mScheduleItemList;
	
	public ScheduleListAdapter(Context context) {
		
		mLayoutInflater = LayoutInflater.from(context);
		
		mScheduleItemList = new ArrayList<ScheduleItem>();
	}
	
	public void setScheduleItemList(List<ScheduleItem> scheduleItemList){
		
		mScheduleItemList.clear();
		mScheduleItemList.addAll(scheduleItemList);
	}
	
	public void clear(){
		
		mScheduleItemList.clear();
	}
	
	@Override
	public int getCount() {
		
		return mScheduleItemList.size();
	}

	@Override
	public Object getItem(int position) {

		return mScheduleItemList.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ScheduleItem scheduleItem = mScheduleItemList.get(position);
		
		View view = ItemViewFactory.createScheduleView(
				mLayoutInflater, 
				scheduleItem.getName(), 
				scheduleItem.getType(), 
				scheduleItem.getLicensePlates(), 
				scheduleItem.getEstimatedMinute(), 
				scheduleItem.getEstimatedStation(), 
				scheduleItem);
		
		return view;
	}
}
